Computer programs typically are made up of components called objects. An object may include both computer instructions and data. Objects of a program may invoke other objects within the program, or external components. An object may be designed to be used as an external component by a program, or by multiple programs. An object may be designed with a defined set of methods and data types, and perform in defined ways, to facilitate use by a variety of programs and programmers. An interface defines access to the object's public methods and data, including the behavior of the methods. With a well-defined interface, an object may be changed and continue to work for programs that invoke it, provided it conforms to the interface.
The Component Object Model (COM), produced by Microsoft Corporation of Redmond, Wash., is a software architecture for creating, communicating with, and using objects. A COM object may have one or more interfaces that expose its attributes and functionality to external components or applications. A software developer may use a COM object without needing to know many of the details of its implementation, and can rely on the interface even if the implementation changes in a future version. The COM architecture allows an object written in a programming language to be used by programs written in different programming languages. A developer of the other programs need not even know the language of the COM object.
A COM interface is a strongly-typed contract between the object and external programs. Each interface has a unique identifier, referred to as a globally unique identifier (GUID). If a COM object implements more than one interface, each interface has its own unique GUID. A GUID is typically a 128-bit integer number. A GUID facilitates correct connection between a COM object and a calling program. If a COM object is updated and requires one or more updated interfaces, each new one has a new corresponding GUID. According to the COM protocol, each new interface must be compatible with previous interfaces. They may add new methods or definitions, but do not change or delete older definitions.
A framework is a software architecture that facilitates sharing of services to applications that run within the framework. For example, a framework may provide services such as memory allocation and deallocation, user interface, exception handling, network communications, managing the lifetime of processes, or other such services. This type of framework may be referred to as a “managed framework,” and programs that execute within such a framework may be referred to as “managed programs.” The .NET framework, by Microsoft Corporation, is an example of such a framework. It provides a framework for application development and execution. The .NET framework includes a runtime environment known as the Common Language Runtime (CLR). The CLR manages programs within the framework, by locating and loading classes, handling references to objects and their methods, allocating and deallocating memory, and other runtime services. A framework may enable a software developer to develop programs using the framework as a platform, facilitating deployment on a variety of different computer systems.
To facilitate use of a COM object from a program in the .NET framework, an interop assembly may be used. An interop assembly is a bridging system that enables interaction between software objects across different architectures, such as the managed architecture of .NET and the unmanaged COM architecture. An interop assembly generally includes metadata that enables interaction between software objects. The metadata of an interop assembly corresponding to a COM object generally includes the interface definitions as well as other metadata that is exposed by the COM object and used by a managed program. The framework can use the metadata of an interop assembly to enable a managed program to use a COM object in a manner similar to using a managed component.
FIG. 1A illustrates a compile-time environment 100 having components from two different architectures. COM component 104 is a component that adheres to the COM architecture. COM component 104 is not a part of compile-time environment 100. It is shown in dashed lines to indicate a relation to compile time environment 100. Specifically, COM component 104 may be used as input to generate interop assembly 106 prior to compilation of application source code 110. As shown in FIG. 1B, COM component 104 may also be used at runtime.
Framework 108a is a platform with an architecture that facilitates and manages execution of programs or subprograms, and further facilitates compilation of programs to be managed. Application source code 110 is source code that is translated by compiler 112 into a managed application 114 that runs within framework 108b of FIG. 1B. Compiler 112 receives as input application source code 110 and interop assembly 106, generating managed application 114.
FIG. 1B illustrates a runtime environment 101, corresponding to compile-time environment 100 of FIG. 1A. Runtime environment 101 includes components from two different architectures. As discussed above, COM component 104 is a component that adheres to the COM architecture. It may be used by one or more computer programs, including programs within framework 108b and programs external to framework 108b. It has an associated VTable 120. Briefly, VTable 120 includes data that facilitates dynamic access to objects, methods, or data during runtime, by providing pointers. For example, VTable 120 may have a table with an entry for each method of the COM component. When an external component needs to invoke a method, it may retrieve, from the VTable, a pointer to the method, and use the pointer to reference the method.
Framework 108b is an architecture that facilitates and manages execution of programs or subprograms. It presents a different view of framework 108a of FIG. 1. Managed application 114 is a managed application that runs within framework 108b. Runtime manager 118 provides services to managed application 114, as discussed above. Runtime manager 118 receives metadata from interop assembly 106 and vtable 120 to facilitate referencing COM component 104.
Interop assembly 106 enables managed application 114 to invoke and use COM component 104. As discussed above, interop assembly 106 includes metadata, such as interface definitions, exposed by COM component 104. When managed application 114 invokes a method of COM component 104, interop assembly 106 may be used to locate and invoke the method. Runtime manager 118 may retrieve a pointer to the method from VTable 120.
In runtime environment 101, prior to executing managed application 114, or at least prior to the use of COM component 104 by managed application 114, interop assembly 106 is deployed, so that it may be used as discussed herein. There may be added complexity in a situation in which there are multiple versions of interop assembly 106, with respect to deploying a correct interop assembly. Further, interop assembly can be large, and deployment or runtime use can use up valuable storage or memory.